package threads;

import java.util.concurrent.*;

/**
 * ThreadWithResult
 *
 * @author flyketch
 * @date 20-6-5 上午9:34
 */
public class ThreadWithResult {

  public static void main(String[] args) {
      ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 10, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue(100));

      // submit 使用
      Future<String> future = threadPoolExecutor.submit(() -> {
          System.out.println("Hello, 树先生.");
          return "Success";
      });
      try {
          System.out.println(future.get());
          // 程序不会退出，需要加退出代码
          System.exit(0);
      } catch (ExecutionException e) {
          e.printStackTrace();
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  }
}
